<!-- 首页-劳动合同-续签沟通 -->
<template>
  <ContentCard>
    <template #header>
      <PageHeaderNew title="续签沟通" />
    </template>

    <TableTurn :tableData="getTableData" ref="tableRef">
      <a-table-column :width="80">
        <template #title> 序号 </template>
        <template #cell="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
      </a-table-column>
      <a-table-column :width="150" title="续签沟通名称" data-index="name" />
      <a-table-column title="备注" data-index="remark" />
      <a-table-column :width="150" title="续签沟通状态" data-index="status">
        <template #cell="{ record }">
          <div
            :style="{
              color: contractRenewalStatus.find(
                ({ value }) => value === record?.renewal
              )?.color
            }"
          >
            {{
              contractRenewalStatus.find(
                ({ value }) => value === record?.renewal
              )?.text || '-'
            }}
          </div>
        </template>
      </a-table-column>
      <a-table-column :width="150" title="操作" data-index="">
        <template #cell="{ record }">
          <a-button
            type="text"
            @click="handle(record)"
            v-if="record?.renewal === 3"
          >
            处理
          </a-button>
          <a-button type="text" @click="handle(record)" v-else> 详情 </a-button>
        </template>
      </a-table-column>
    </TableTurn>
  </ContentCard>
</template>

<script lang="ts" setup>
import {
  GetUserRenewCommunicatePage,
  EditUserRenewState
} from '@/apis/management/contract/baseSetting';
import { GetLegalEntityList } from '@/apis/management/organization/organizationManagement/LegalEntity/index';
import { GetContractGroup } from '@/apis/management/contract/baseSetting';
import { contractRenewalStatus } from '@/utils/dictionary/contract';
import { GetMyContractPage } from '@/apis/management/contract/contractManagement/haveSigned';

const router = useRouter();

const getTableData = async (pageData?: any) => {
  try {
    let res = await GetUserRenewCommunicatePage({
      ...pageData,
      id: localStorage.getItem('userId')
    });
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};

// 处理或者查看详情 type 1处理 2查看
const handle = ({ id }: any) => {
  router.push({
    name: 'RenewalCommunicationDetails',
    query: { id }
  });
};

let typeList = ref<any[]>([]);
let companyList = ref<any[]>([]);
let loadData = async () => {
  let [contractType, legalEntity] = await Promise.all([
    GetContractGroup({
      pageNumber: 0,
      pageSize: -1
    }),
    GetLegalEntityList({ pageNumber: 0, pageSize: -1 } as any)
  ]);
  typeList.value = contractType?.content || [];
  companyList.value = legalEntity?.content || [];
};
loadData();
</script>

<style lang="less" scoped></style>
